package com.von.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.von.entity.DictionaryItem;
import com.von.param.DictionaryItemParam;
import com.von.result.R;
import com.von.service.IDictionaryItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 字典-项 前端控制器
 * </p>
 *
 * @author xiaosai
 * @since 2021-07-09
 */
@RestController
@RequestMapping("/dictionaryItem")
public class DictionaryItemController {
    /**
     * @apiDefine dictionaryItem 字典项
     */

    @Autowired
    private IDictionaryItemService iDictionaryItemService;

    /**
     * @api {post} /dictionaryItem/list 分页获取
     * @apiGroup dictionaryItem
     * @apiParam {Integer} groupId 字典组id[必填]
     * @apiParam {Integer} pageNum 当前页[必填]
     * @apiParam {Integer} pageSize 页面条数[必填]
     * @apiParamExample {json} Request-Example:
     * {
     *     "groupId":1,
     *     "pageNum":1,
     *     "pageSize":10
     * }
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping("/list")
    public R<Page<DictionaryItem>> list(@RequestBody DictionaryItemParam dictionaryItemParam){
        return iDictionaryItemService.list(dictionaryItemParam);
    }

    /**
     * @api {post} /dictionaryItem/add 添加
     * @apiGroup dictionaryItem
     * @apiParam {Integer} groupId 字典组id[必填]
     * @apiParam {String} code 编码[必填]
     * @apiParam {String} value 名称[必填]
     * @apiParam {String} remark 备注
     * @apiParamExample {json} Request-Example:
     * {
     *     "groupId":1,
     *     "code":"dataDemo",
     *     "value":"dataDemo",
     *     "remark":"dataDemo"
     * }
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody DictionaryItem dictionaryItem){
        return iDictionaryItemService.add(dictionaryItem);
    }

    /**
     * @api {post} /dictionaryItem/update 更新
     * @apiGroup dictionaryItem
     * @apiParam {Integer} id 字典项id[必填]
     * @apiParam {String} code 编码[必填]
     * @apiParam {String} value 名称[必填]
     * @apiParam {String} remark 备注
     * @apiParamExample {json} Request-Example:
     * {
     *     "id":1,
     *     "code":"dataDemo",
     *     "value":"dataDemo",
     *     "remark":"dataDemo"
     * }
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping("/update")
    public R<String> update(@RequestBody DictionaryItemParam dictionaryItemParam){
        return iDictionaryItemService.update(dictionaryItemParam);
    }

    /**
     * @api {get} /dictionaryItem/update 删除
     * @apiGroup dictionaryItem
     * @apiParam {Integer} id 字典项id[必填]
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @GetMapping("/del")
    public R<String> del(Integer id){
        return iDictionaryItemService.del(id);
    }

    /**
     * @api {get} /dictionaryItem/export 导出
     * @apiGroup dictionaryItem
     * @apiParam {Integer} groupId 字典项id[必填]
     */
    @GetMapping("/export")
    public void exportDictionaryItem(HttpServletResponse response,Integer groupId){
        iDictionaryItemService.exportDictionaryItem(response,groupId);
    }

    /**
     * @api {get} /dictionaryItem/download 下载模板
     * @apiGroup dictionaryItem
     */
    @GetMapping("/download")
    public void downloadDictionaryItem(HttpServletResponse response){
        iDictionaryItemService.downloadDictionaryItem(response);
    }

    /**
     * @api {post} /dictionaryItem/import 导入
     * @apiGroup dictionaryItem
     * @apiParam {MultipartFile} file 文件
     * @apiParam {Integer} groupId 字典项id[必填]
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping("/import")
    public R<String> importDictionaryItem(@RequestParam("file") MultipartFile file,@RequestParam("groupId") Integer groupId){
        return iDictionaryItemService.importDictionaryItem(file,groupId);
    }
}
